home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1458.dms / var1458.adf / IDCMP / Example9.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  8KB  |  198 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: IDCMP                       Tulevagen 22       */
  8. /* File:    Example9.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program explains how to use the IDCMP flag REFRESHWINDOW, and */
  21. /* how to optimize the redrawing of the window.                       */
  22.  
  23.  
  24.  
  25. #include <intuition/intuition.h>
  26.  
  27.  
  28.  
  29. struct IntuitionBase *IntuitionBase;
  30.  
  31.  
  32.  
  33. /* Declare a pointer to a Window structure: */ 
  34. struct Window *my_window;
  35.  
  36. /* Declare and initialize your NewWindow structure: */
  37. struct NewWindow my_new_window=
  38. {
  39.   50,             /* LeftEdge    x position of the window. */
  40.   25,             /* TopEdge     y positio of the window. */
  41.   320,            /* Width       320 pixels wide. */
  42.   100,            /* Height      100 lines high. */
  43.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  44.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  45.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  46.                   /*             selects the Close window gad.           */
  47.  
  48.   REFRESHWINDOW,  /*             We will recieve a message whenever we */
  49.                   /*             need to refresh (redraw) the window. */
  50.  
  51.   SIMPLE_REFRESH| /* Flags       Your program has to refresh the window. */
  52.   WINDOWCLOSE|    /*             Close Gadget. */
  53.   WINDOWDRAG|     /*             Drag gadget. */
  54.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  55.   WINDOWSIZING|   /*             Sizing Gadget. */
  56.   ACTIVATE,       /*             The window should be Active when opened. */
  57.   NULL,           /* FirstGadget No gadgets connected to this window. */
  58.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  59.   "UPDATE ME",    /* Title       Title of the window. */
  60.   NULL,           /* Screen      Connected to the Workbench Screen. */
  61.   NULL,           /* BitMap      No Custom BitMap. */
  62.   100,            /* MinWidth    We will not allow the window to become */
  63.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  64.   400,            /* MaxWidth    than 400 x 200. */
  65.   200,            /* MaxHeight */
  66.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  67. };
  68.  
  69.  
  70.  
  71. /*************************************************************************/
  72. /* Extra information:                                                    */
  73. /* We will recieve a REFRESHWINDOW message whenever we need to redraw    */
  74. /* the window's display. If the window is a SuperBitmap window you never */
  75. /* need to redraw it since it has its own BitMap. However, if the window */
  76. /* is of the type SIMPLE_REFRESH or SMART_REFRESH it can happen that     */
  77. /* your program need to redraw the window.                               */
  78. /* SIMPLE_REFRESH: You need to update the window if it is resized,       */
  79. /*                 pushed from behind to the front, or is moved.         */
  80. /* SMART_REFRESH:  You need to update the display if it is resized.      */
  81. /*                                                                       */
  82. /* Once you recieve the message you should redraw the window. However,   */
  83. /* before you start to redraw you need to call the function:             */
  84. /* BeginRefresh(), and when you have finished you should call the        */
  85. /* function EndRefresh(). (Even if you do not redraw anything, you       */
  86. /* should call these functions.) The functions will improve the speed of */
  87. /* the redrawing since only the trashed parts will be redrawed.          */
  88. /*************************************************************************/
  89.  
  90.  
  91.  
  92. main()
  93. {
  94.   /* Boolean variable used for the while loop: */
  95.   BOOL close_me;
  96.  
  97.   ULONG class;   /* IDCMP flag. */
  98.  
  99.   /* Pointer to an IntuiMessage structure: */
  100.   struct IntuiMessage *my_message;
  101.  
  102.  
  103.  
  104.   /* Before we can use Intuition we need to open the Intuition Library: */
  105.   IntuitionBase = (struct IntuitionBase *)
  106.     OpenLibrary( "intuition.library", 0 );
  107.   
  108.   if( IntuitionBase == NULL )
  109.     exit(); /* Could NOT open the Intuition Library! */
  110.  
  111.  
  112.  
  113.   /* We will now try to open the window: */
  114.   my_window = (struct Window *) OpenWindow( &my_new_window );
  115.   
  116.   /* Have we opened the window succesfully? */
  117.   if(my_window == NULL)
  118.   {
  119.     /* Could NOT open the Window! */
  120.     
  121.     /* Close the Intuition Library since we have opened it: */
  122.     CloseLibrary( IntuitionBase );
  123.  
  124.     exit();  
  125.   }
  126.  
  127.  
  128.  
  129.   /* We have opened the window, and everything seems to be OK. */
  130.  
  131.  
  132.  
  133.   close_me = FALSE;
  134.  
  135.   /* Stay in the while loop until the user has selected the Close window */
  136.   /* gadget: */
  137.   while( close_me == FALSE )
  138.   {
  139.     /* Wait until we have recieved a message: */
  140.     Wait( 1 << my_window->UserPort->mp_SigBit );
  141.  
  142.  
  143.     /* As long as we can collect messages successfully we stay in the */
  144.     /* while-loop: */
  145.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  146.     {
  147.       /* After we have successfully collected the message we can read */
  148.       /* it, and save any important values which we maybe want to check */
  149.       /* later: */
  150.       class = my_message->Class;     /* IDCMP flag. */
  151.       
  152.  
  153.       /* After we have read it we reply as fast as possible: */
  154.       /* REMEMBER! Do never try to read a message after you have replied! */
  155.       /* (Some other process has maybe changed it.) */
  156.       ReplyMsg( my_message );
  157.  
  158.  
  159.       /* Check which IDCMP flag was sent: */
  160.       switch( class )
  161.       {
  162.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  163.                close_me=TRUE;
  164.                break;
  165.  
  166.         case REFRESHWINDOW:  /* You need to update the window. */
  167.                printf("We need to redraw the window! (Well almost)\n");
  168.                
  169.                /* Start the redrawing: */
  170.                BeginRefresh( my_window );
  171.                
  172.                /* Redraw the window. For example call the function       */
  173.                /* RefreshGadgets(), DrawImage(), DrawBorder() etc...     */
  174.                /* In this example we do not redraw anything (there does  */
  175.                /* not exist anything to redraw). However, even if you do */
  176.                /* nothing you need to call the functions BeginRefresh()  */
  177.                /* and EndRefresh().                                      */
  178.                
  179.                /* End the redrawing: */
  180.                EndRefresh( my_window );
  181.                break;
  182.       }
  183.     }
  184.   }
  185.  
  186.  
  187.  
  188.   /* Close the window: */
  189.   CloseWindow( my_window );
  190.  
  191.  
  192.  
  193.   /* Close the Intuition Library: */
  194.   CloseLibrary( IntuitionBase );
  195.   
  196.   /* THE END */
  197. }
  198.